import tools from "../utils/tools.js";
import validate from "../utils/validate.js";
import systemInfo from "../utils/systemInfo.js";
import router from "../utils/router.js";

export default {
  data() {
    return {};
  },
  onLoad() {},
  computed: {
    $sc() {
      return {
        push: router.push.bind(router),
        back: router.back.bind(router),
        ...tools,
        ...validate,
        sys: systemInfo,
      };
    },
  },
  methods: {
    $scGetRect(selector, all) {
      return new Promise((resolve) => {
        uni
          .createSelectorQuery()
          .in(this)
          [all ? "selectAll" : "select"](selector)
          .boundingClientRect((rect) => {
            if (all && Array.isArray(rect) && rect.length) {
              resolve(rect);
            }
            if (!all && rect) {
              resolve(rect);
            }
          })
          .exec();
      });
    },
  },
  created() {},
};
